#include "mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    xc=100; yc=300; r=20; col=0;

}

MainWindow::~MainWindow()
{
}
void MainWindow::keyPressEvent(QKeyEvent *event)
{
    switch (event->key())
    {
    case Qt::Key_W: if(yc-r>0) { yc--; update();}
        break;
    case Qt::Key_S: if(yc+r<480) { yc++; update();}
        break;
    case Qt::Key_A: if(xc-r>0) { xc--; update();}
        break;
    case Qt::Key_D: if(xc+r<640) { xc++; update();}
        break;
    case Qt::Key_R: if(r<200) { r++; update();}
        break;
    case Qt::Key_F: if(r>10) { r--; update();}
        break;
    case Qt::Key_Space:  col=(col+1)%6; update();
        break;
    }
}
void MainWindow::paintEvent(QPaintEvent *event)
{
    QPainter paint(this);
    paint.setRenderHint(QPainter::Antialiasing, true);
    switch (col)
    {
    case 0: paint.setBrush(QBrush(Qt::white));
        break;
    case 1: paint.setBrush(QBrush(Qt::black));
      }
    krug(&paint, xc, yc, r);
}
void MainWindow::krug(QPainter *paint, int cx, int cy, int r)
{
    paint->drawEllipse(cx-r, cy-r, 2*r, 2*r);
}
void MainWindow::Draw(QPainter *paint)
{
    krug(paint, 200, 100, 100);
}
